﻿using ORM.EF.Context;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace ORM.EF
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            this.Loaded += MainWindow_Loaded;
            this.Closed += MainWindow_Closed;
        }

        private void MainWindow_Closed(object sender, EventArgs e)
        {
            dbCtx.Dispose();
        }

        private DBContext dbCtx;

        private void MainWindow_Loaded(object sender, RoutedEventArgs e)
        {
            this.ucInfo_supplers.OnBtnClick += UcInfo_supplers_OnBtnClick;
            dbCtx = new DBContext();
        }

        private void UcInfo_supplers_OnBtnClick(object sender, EventArgs e)
        {
            var str = sender.ToString();
            switch (str)
            {
                case "new":
                    dbCtx.Suppliers.Add(new Models.Supplier()
                    {
                        SNo = "2021_"+Environment.TickCount.ToString(),
                        SName = "New Suppler",
                        Address = "China",
                        Tele="1234567890",
                         Account = "Acc_2021"
                    });
                    dbCtx.SaveChanges();
                    break;
                default:
                    break;
            }
        }
    }
}
